package com.puman.houmu.puman.Fragment;

import android.app.Fragment;                              //不奔溃
import android.os.Bundle;
import android.support.annotation.Nullable;
//import android.support.v4.app.Fragment;                    //奔溃
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.puman.houmu.puman.Guide.EatFragment;
import com.puman.houmu.puman.R;
import com.flyco.tablayout.SlidingTabLayout;
import com.puman.houmu.puman.Search.fragment.BaseFragment;
import com.puman.houmu.puman.Search.fragment.FragmentBanzheng;
import com.puman.houmu.puman.Search.fragment.FragmentTuijian;
import com.puman.houmu.puman.Search.fragment.FragmentZujin;
import com.wyt.searchedittext.SearchEditText;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by layne on 2017/8/4.
 */

public class GuideFragment extends Fragment implements SearchEditText.OnSearchClickListener,View.OnClickListener
{

    //搜索
    private SearchEditText searchEditText;

    @InjectView(R.id.tablayout)
    SlidingTabLayout tablayout;
    @InjectView(R.id.view_pager)
    ViewPager viewPager;
    private ArrayList<BaseFragment> mFragments = new ArrayList<>();
    private String[] mTitles = {"推荐","网签办证","租金方案","吃喝玩乐"};
    private MyPagerAdapter adapter;

    View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_guide, container,false);
        searchEditText = (SearchEditText)view.findViewById(R.id.GuidsearchEditText);
        searchEditText.setOnSearchClickListener(this);
        ButterKnife.inject(this,view);
        initView();
        return view;
    }

    private void initView(){
        mFragments.add(FragmentTuijian.getInstance(mTitles[0]));
        mFragments.add(FragmentBanzheng.getInstance(mTitles[1]));
        mFragments.add(FragmentZujin.getInstance(mTitles[2]));
        mFragments.add(EatFragment.getInstance(mTitles[3]));
        //getSupportFragmentManger() 嵌套在Activity中用这个
        adapter = new MyPagerAdapter(getChildFragmentManager());
    }

    @Override
    public void onSearchClick(View view) {
        Toast.makeText(getActivity(),"搜索吧",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {

    }


    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public android.support.v4.app.Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }















}
